﻿using System;
using System.Drawing;
using System.Windows.Forms;

namespace RichEditor
{
    public partial class Form1 : Form
    {
        string path;
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            path = null;
            richTextBox1.Text = null;
        }

        private void button2_Click(object sender, EventArgs e)
        {
            if(openFileDialog1.ShowDialog()== DialogResult.OK)
            {
                path = openFileDialog1.FileName;
                richTextBox1.LoadFile(path);
            }
        }

        private void button3_Click(object sender, EventArgs e)
        {
            if(path == null)
            {
                if(saveFileDialog1.ShowDialog() == DialogResult.OK)
                {
                    path = saveFileDialog1.FileName;
                    richTextBox1.SaveFile(path);
                }
            }
            else
            {
                richTextBox1.SaveFile(path);
            }
        }
        
        private void button4_Click(object sender, EventArgs e)
        {
            if(richTextBox1.SelectedText != null)
            {
                richTextBox1.SelectionFont = new Font(Font.FontFamily, Font.Size + 2, Font.Style);
            }
        }

        private void button5_Click(object sender, EventArgs e)
        {
            if (richTextBox1.SelectedText != null)
            {
                richTextBox1.SelectionColor = Color.Red;
            }
        }
    }
}
